<template>
	<view class="page">
		<view
			class="flex flex-direction flex-wrap align-stretch justify-center benben-position-layout flex aboutUs_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between aboutUs_fd0_0'>
				<view class='flex flex-wrap align-center aboutUs_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
					data-url="1">
					<image class='aboutUs_fd0_0_c0_c0' mode="aspectFill" :src='STATIC_URL+"56.png"'></image>
				</view>
				<text class='aboutUs_fd0_0_c1'>成为学员</text>
				<view class='flex align-center justify-end aboutUs_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#1593FF"></u-loading>
			<view>加载中</view>
		</view>
		
		<view v-else>
			<view class="bg_1">
				<image :src='STATIC_URL+"12.png"' mode="aspectFill"></image>
			</view>
			<view class="bg_2">
				<image :src='STATIC_URL+"100.png"' mode="aspectFill"></image>
			</view>
			<view class="quanyi">
				<view class="quanyi_title">享有权益</view>
				<view class="quanyi_content">
					<view class="quanyi_item">
						<image :src='STATIC_URL+"19.png"' mode=""></image>
						<view class="quanyi_item_text">全科试题训练</view>
					</view>
					<view class="quanyi_item">
						<image :src='STATIC_URL+"94.png"' mode=""></image>
						<view class="quanyi_item_text">全科试题讲解</view>
					</view>
					<view class="quanyi_item">
						<image :src='STATIC_URL+"95.png"' mode=""></image>
						<view class="quanyi_item_text">历年真题模拟</view>
					</view>
				</view>
			</view>
			<view class="pay_btn" @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/my/becomeStudent/paySuccess`">
				<view class="agreement" @tap.stop="selectAgree">
					<image v-if="!is_agree" :src='STATIC_URL+"8.png"' mode=""></image>
					<image v-else :src='STATIC_URL+"7.png"' mode=""></image>
					<text>开通前请阅读</text>
					<text class="agreement_1" @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/denglu/agreement/agreement?aid=5`">《鼎承教育》</text>
					<text>相关协议</text>
				</view>
				<view class="btn_content" @tap.stop="generateOrder">
					<text class="btn_content_1">￥{{Number(vipData.jiage)}} 确认协议并支付</text>
					<text class="btn_content_2">有效期永久</text>
				</view>
			</view>
		</view>
		<view :style="{height: '200rpx'}"></view>

	</view>
</template>
<script>
	export default {
		components: {},

		data() {
			return {
				isShow: true,
				isClick: false,
				vipData: {},
				is_agree: false,
			};
		},
		computed: {
			
		},
		watch: {},
		onLoad(options) {
			this.getVip();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			selectAgree() {
				this.is_agree = !this.is_agree;
			},
			getVip() {
				this.$api.post(global.apiUrls.post65aa39b188790, {
					
				}).then(res => {
					this.isShow = false;
					if (res.data.code == 1) {
						this.vipData = res.data.data;
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			// 生成订单  post65aa4571edab7
			generateOrder() {
				let _this = this;
				if (_this.isClick) return;
				if (!_this.is_agree) {
					_this.$message.info('请阅读并同意会员服务协议');
					return;
				}
				_this.isClick = true;
				_this.$api.post(global.apiUrls.post65aa4571edab7, {
					aid: _this.id
				}).then(res => {
					console.log(res);
					if (res.data.code == 1) {
						_this.getPayInfo(res.data.data.dingdanhao);
					} else {
						_this.$message.info(res.data.msg);
						_this.isClick = false;
					}
				})
			},
			// 获取支付信息  post65a9d7d8943ff
			getPayInfo(order_sn) {
				this.$api.post(global.apiUrls.post65a9d7d8943ff, {
					dingdanhao: order_sn,
					type: 1
				}).then(res => {
					if (res.data.code == 1) {
						let data = res.data.data;
						console.log('支付信息', data);
						uni.requestPayment({
							provider: 'wxpay',
							// #ifdef MP-WEIXIN
							timeStamp: data.timeStamp,
							nonceStr: data.nonceStr,
							package: data.package,
							signType: data.signType,
							paySign: data.paySign,
							// #endif
							// #ifdef APP-PLUS
							orderInfo: data,
							// #endif
							success: e => {
								console.log('success', e);
								if (e.errMsg == 'requestPayment:ok') {
									this.$message.info('购买成功');
									setTimeout(() => {
										this.isClick = false;
										uni.navigateBack();
									}, 800)
								}
							},
							fail: e => {
								this.isClick = false;
								console.log('fail', e);
								// #ifdef APP-PLUS
								let failMsg = 'requestPayment:fail canceled';
								// #endif
								// #ifndef APP-PLUS
								let failMsg = 'requestPayment:fail cancel';
								// #endif
								if (e.errMsg == failMsg) {
									this.$message.info(this.$t('取消支付'));
								} else {
									this.$message.info(this.$t('支付失败,请稍后重试'));
									// this.$message.info("支付失败,原因为: " + e.errMsg);
								}
							},
							complete: () => {
								
							}
						});
					} else {
						this.$message.info(res.data.msg);
						this.isClick = false;
					}
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.bg_1 {
		width: 100%;
		height: 348rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}
	.bg_2 {
		width: 686rpx;
		height: 190rpx;
		margin: -70rpx auto 0;
		image {
			width: 100%;
			height: 100%;
			border-radius: 16rpx;
		}
	}
	.quanyi {
		padding: 32rpx;
		.quanyi_title {
			font-size: 36rpx;
			font-weight: 500;
			margin-bottom: 32rpx;
		}
		.quanyi_content {
			display: flex;
			justify-content: space-between;
			.quanyi_item {
				text-align: center;
				image {
					width: 100rpx;
					height: 100rpx;
					margin-bottom: 16rpx;
				}
				.quanyi_item_text {
					font-size: 28rpx;
				}
			}
		}
	}
	.pay_btn {
		padding: 0 32rpx 40rpx;
		position: fixed;
		width: 100%;
		bottom: 0;
		left: 0;
		.agreement {
			font-size: 24rpx;
			color: #999999;
			margin-bottom: 32rpx;
			display: flex;
			align-items: center;
			image {
				width: 30rpx;
				height: 30rpx;
				margin-right: 16rpx;
			}
			.agreement_1 {
				color: #2BA5FF;
			}
		}
		.btn_content {
			width: 686rpx;
			height: 88rpx;
			line-height: 88rpx;
			background: linear-gradient(90deg, #1593FF 0%, #8AC9FF 100%);
			border-radius: 82rpx;
			text-align: center;
			position: relative;
			.btn_content_1 {
				display: inline-block;
				color: #fff;
				font-size: 36rpx;
				font-weight: bold;
				transform: translateX(-10rpx);
			}
			.btn_content_2 {
				font-size: 26rpx;
				color: #1869AF;
				position: absolute;
				right: 32rpx;
				top: 2rpx;
			}
		}
	}
	.aboutUs_fd2_0 {
		color: #BFBFBF;
		font-size: 28rpx;
		font-weight: 400;
		line-height: 40rpx;
		white-space: pre-wrap;
		margin: 0rpx 0rpx 8rpx 0rpx;
	}

	.aboutUs_fd2_1 {
		color: #BFBFBF;
		font-size: 28rpx;
		font-weight: 400;
		line-height: 40rpx;
	}

	.aboutUs_flex_2 {
		width: 750rpx;
		height: 90rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(80rpx + var(--window-bottom));
	}

	.aboutUs_fd1_0 {
		width: 180rpx;
		height: 180rpx;
		border-radius: 36rpx 36rpx 36rpx 36rpx;
		margin: 90rpx 0rpx 0rpx 0rpx;
	}

	.aboutUs_fd1_1 {
		margin: 32rpx 0rpx 0rpx 0rpx;
	}

	.aboutUs_fd1_1_c0 {
		font-weight: 400;
		color: #333333;
		font-size: 28rpx;
		line-height: 40rpx;
	}

	.aboutUs_fd1_1_c1 {
		font-weight: 400;
		color: #333333;
		font-size: 28rpx;
		line-height: 40rpx;
	}

	.aboutUs_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.aboutUs_fd0_0_c0 {
		width: 40rpx;
		height: 40rpx;
	}

	.aboutUs_fd0_0_c0_c0 {
		width: 18rpx;
		height: 32rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.aboutUs_fd0_0_c1 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
		line-height: 50rpx;
	}

	.aboutUs_fd0_0_c2 {
		width: 40rpx;
		height: 40rpx;
	}

	.aboutUs_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: #fff;
		background-size: 100% auto !important;
	}
</style>
